import ArrayList from '@/sources/ArrayList'
import Assert from '@/utils/assets'
import { toString } from '@/utils';

export const test = () => {
    const arr = new ArrayList();
    const assert = new Assert();
    assert.type('size').expect(arr.size()).toBe(0)
    assert.type('capicity').expect(arr.capicity).toBe(10)
    assert.type('isEmpty').expect(arr.isEmpty()).toBe(true)
    assert.type('contains').expect(arr.contains(1)).toBe(false)
    arr.add(1);
    arr.add(2);
    arr.add(3);
    arr.add(4);
    arr.add(5);
    arr.add(6);
    arr.add(7);
    arr.add(8);
    arr.add(9);
    arr.add(10);
    assert.type('size').expect(arr.size()).toBe(10)
    assert.type('capicity').expect(arr.capicity).toBe(10)
    arr.add(11);
    assert.type('capicity').expect(arr.capicity).toBe(20)
    assert.type('contains').expect(arr.contains(1)).toBe(true)

    assert.type('get').expect(arr.get(1)).toBe(2)
    assert.type('set').expect((arr.set(1, 100), arr.get(1))).toBe(100)

    arr.addToIndex(1, 200);
    assert.type('addToIndex').expect(arr.indexOf(200)).toBe(1)
    // toStringArr(arr)
    arr.remove(1)
    assert.type('contains').expect(arr.contains(200)).toBe(false)
    assert.type('sizes').expect(arr.size()).toBe(11)
    // toStringArr(arr)
    assert.type('indexOf').expect(arr.indexOf(100)).toBe(1)

    arr.add(1);
    assert.type('lastIndexOf').expect(arr.lastIndexOf(1)).toBe(11)
    
    arr.clear();
    assert.type('clear').expect(arr.size()).toBe(0).expect(arr.array.length).toBe(0)
    // toStringArr(arr)
}

export const testObject = () => {
    const arr = new ArrayList();
    const assert = new Assert();
    // const obj = {name: 'hchlq'};
    // arr.add(obj);
    // assert.type('contains').expect(arr.contains(obj)).toBe(true)
    // assert.type('size').expect(arr.size()).toBe(1)
    arr.add(1);
    arr.add(2);
    arr.add(3);
    arr.add(4);
    arr.add(5);
    arr.add(6);
    arr.add(7);
    arr.add(8);
    arr.add(9);
    arr.add(10);
    toStringArr(arr)
}


/**
 * 测试辅助方法
 */
export const testArrHelpMethod = () => {
    const arr = new ArrayList();
    const assert = new Assert();

    arr.add(1);
    arr.add(2);
    toStringArr(arr)
    assert.type('size').expect(arr.size()).toBe(2)
    assert.type('pop').expect(arr.pop()).toBe(2)
    assert.type('size').expect(arr.size()).toBe(1)
    arr.unshift(3)
    arr.unshift(4)
    assert.type('size').expect(arr.size()).toBe(3)

    assert.type('shift').expect(arr.shift()).toBe(4)
    assert.type('size').expect(arr.size()).not().toBe(3)
    arr.forEach((ele, index) => {
        console.log(ele, index);
        return false
    })

    toStringArr(arr)
}

const toStringArr = <T>(arr: ArrayList<T>) => {
    toString('array', arr.array)
}
